<template>
	<view class="appointment">
		<nav>
			<image :src="$imgUrl+obj.avatar"></image>
			<view>
				<nav>
					<view>{{obj.username}}
						<span>{{obj.score}}分</span>
					</view>
					<p @click="skip('/pages/watchComment/watchComment?id='+id)">评价({{obj.evaluate_count}})<u-icon
							name="arrow-right" color="#08702E" size="10"></u-icon></p>
				</nav>
				<span>{{obj.intro}}</span>
				<footer @click="skip('/pages/shop/shop?id='+id)">
					<p>
						<image src="../../static/technician/36.png"></image>实名认证
					</p>
					<p>
						<image src="../../static/technician/36.png"></image>爽约包退
					</p>
					<p>
						<image src="../../static/technician/36.png"></image>资质证书<u-icon name="arrow-right"
							color="#343434" size="6"></u-icon>
					</p>
				</footer>
			</view>
		</nav>
		<view class="main">
			<view v-for='(value,index) in data' :key="value.id">
				<image :src="$imgUrl+value.goods_image"></image>
				<view>
					<p>
						{{value.goods_name}}
						<image src="../../static/home/27.png"></image>
						<span>{{value.duration}}分钟</span>
					</p>
					<view>
						<p>{{value.goods_price}}<span>元{{value.unit?'/'+value.unit:''}}</span></p>
						{{value.goods_virtual_sales}}人选择
					</view>
				</view>
				<footer>
					<p @click='minus(index)'>-</p>
					<input @input="input(index)" type="number" v-model="arr[index].num">
					<p @click='plus(index)'>+</p>
				</footer>
			</view>
		</view>
		<!-- <footers url='/pages/orderForGoods/orderForGoods' :price='495'></footers> -->
		<view class="footer">
			<view>
				<span>合计：</span>
				<p>￥{{price}}</p>
			</view>
			<button @click="skip1('/pages/orderForGoods/orderForGoods')">提交订单</button>
		</view>
	</view>
</template>

<script>
	import footers from '../../components/footers/footers.vue'
	export default {
		components: {
			footers
		},
		data() {
			return {
				arr: [],
				index: "",
				id: '',
				data: [],
				price: 0,
				type: 0,
				obj: {},
				price: '',
				order_sn: ''
			};
		},
		onShow() {
			uni.removeStorageSync('xzdz')
			uni.removeStorageSync('work_time')
		},
		onLoad(res) {
			uni.removeStorageSync('goods_num')
			uni.removeStorageSync('work_time')
			this.type = res.type || 0
			this.id = res.id
			this.price = res.price || ''
			this.order_sn = res.order_sn || ''
			this.getTechGoodsList()
		},
		methods: {
			getTechGoodsList() {
				this.$httpRequest('/tech/getTechGoodsList', {
					tech_id: this.id,
					goods_price: this.price,
					order_sn: this.order_sn
				}).then(res => {
					// console.log(res)
					this.data = res.data.list
					this.obj = res.data.info

					res.data.list.forEach(value => {
						this.arr.push({
							id: value.id,
							num: 0
						})
					})
				})
			},
			skip(url) {
				uni.navigateTo({
					url,
				})
			},
			skip1(url) {
				if (this.index === '') {
					uni.showToast({
						icon: "error",
						title: "请选择服务",
						duration: 2000
					});
					return;
				}
				let goodsInfo = this.data[this.index];
				// console.log(goodsInfo)
				url = url + '?goods_id=' + goodsInfo.goods_id + '&tech_id=' + this.id + '&type=' + this.type +
					'&order_sn=' + this.order_sn + '&num=' + this.arr[this.index].num
				uni.navigateTo({
					url,
				})
			},
			// 减
			minus(index) {
				if (this.arr[index].num >= 1) {
					this.index = index
					this.arr[index].num -= 1;
					this.price = this.data[index].goods_price * this.arr[index].num
					this.arr.forEach((value, ins) => {
						if (ins != index) {
							this.arr[ins].num = 0
						}
					})
				}
			},
			// 加
			plus(index) {
				this.index = index
				console.log(this.type)
				if (this.type == 1000) {
					this.arr[index].num += 1;
				} else {
					this.arr[index].num = 1;
				}
				this.price = this.data[index].goods_price * this.arr[index].num
				this.arr.forEach((value, ins) => {
					if (ins != index) {
						this.arr[ins].num = 0
					}
				})
			},
			input(index) {
				this.index = index
				if (Number(this.arr[index].num) < 0) {
					this.arr[index].num = 0
				}
				this.arr.forEach((value, ins) => {
					if (ins != index) {
						this.arr[ins].num = 0
					}
				})
				this.price = this.data[index].goods_price * this.arr[index].num
			}
		}
	}
</script>

<style lang="less">
	.appointment {
		.footer {
			width: 690rpx;
			height: 130rpx;
			position: fixed;
			bottom: 0;
			left: 50%;
			transform: translateX(-50%);
			border-radius: 20rpx;
			background: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			box-sizing: border-box;

			&>view {
				display: flex;
				font-size: 13px;

				&>p {
					display: flex;
					flex-direction: column;
					align-items: center;
					font-size: 13px;

					&>span {
						font-size: 10px;
						color: #FF4815;
					}
				}
			}

			&>button {
				margin: 0;
				padding: 0;
				width: 180rpx;
				height: 68rpx;
				background: #52C276;
				color: #fff;
				line-height: 68rpx;
			}
		}

		&>.main {
			width: 100%;
			background: #F0F0F0;
			border-radius: 32rpx 32rpx 0 0;
			transform: translateY(-30rpx);
			padding: 24rpx 30rpx;
			box-sizing: border-box;

			&>view {
				width: 100%;
				height: 136rpx;
				background: #fff;
				border-radius: 20rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;
				margin-bottom: 20rpx;

				&>footer {
					display: flex;

					&>input {
						width: 100rpx;
						text-align: center;
					}

					&>p {}
				}

				&>image {
					width: 176rpx;
					height: 112rpx;
					border-radius: 20rpx;
					margin: 10rpx;
					image-rendering: -moz-crisp-edges;
					image-rendering: -o-crisp-edges;
					image-rendering: -webkit-optimize-contrast;
					image-rendering: crisp-edges;
					-ms-interpolation-mode: nearest-neighbor;
				}

				&>view {
					&>view {
						color: #9E9E9E;
						font-size: 8px;

						&>p {
							color: #52C276;
							font-size: 15px;

							&>span {
								font-size: 8px;
							}
						}
					}

					&>p {
						font-size: 13px;
						color: #333333;

						&>image {
							width: 20rpx;
							height: 20rpx;
							margin: 0 10rpx 0 28rpx;
						}

						&>span {
							font-size: 8px;
							color: #9E9E9E;
						}
					}
				}
			}
		}

		&>nav {
			width: 100%;
			background: linear-gradient(180deg, #53C277 0%, #81E2A8 100%);
			display: flex;
			padding-bottom: 30rpx;
			padding-top: 20rpx;

			&>view {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-evenly;
				padding-right: 20rpx;
				box-sizing: border-box;

				&>nav {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 40rpx;

					&>view {
						font-size: 15px;
						color: #333333;
						display: flex;
						align-items: center;

						&>span {
							color: #08702E;
							font-size: 12px;
							margin-left: 20rpx;
						}
					}

					&>p {
						display: flex;
						font-size: 12px;
						color: #08702E;

						&>.u-icon {
							transform: translateY(4rpx);
							margin-left: 18rpx;
						}
					}
				}

				&>footer {
					font-size: 10px;
					color: #343434;
					display: flex;
					justify-content: space-between;

					&>p {
						display: flex;
						align-items: center;

						&>image {
							width: 20rpx;
							height: 20rpx;
							margin-right: 10rpx;
						}

						&>.u-icon {
							margin-left: 10rpx;
							transform: translateY(4rpx);
						}
					}
				}

				&>span {
					font-size: 12px;
					color: #08702E;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box !important;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					margin: 40rpx 0 20rpx 0;
				}
			}

			&>image {
				width: 160rpx;
				height: 224rpx;
				margin: 20rpx 30rpx;
				image-rendering: -moz-crisp-edges;
				image-rendering: -o-crisp-edges;
				image-rendering: -webkit-optimize-contrast;
				image-rendering: crisp-edges;
				-ms-interpolation-mode: nearest-neighbor;
			}
		}
	}
</style>